<?php

namespace app\admin\model;

use app\admin\common\Common;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\Model;

class NotesModel extends Model
{
    public static function searchnotes($data){
        try {
            $db = Db::name('notes')
                ->alias('n')
                ->join('app a', 'a.appid = n.appid')
                ->field('a.appname,n.*')
                ->where('id', $data['id'])
                ->find();
        } catch (DataNotFoundException $e) {
             return Common::result(400,$e->getMessage());
        } catch (ModelNotFoundException $e) {
             return Common::result(400,$e->getMessage());
        } catch (DbException $e) {
             return Common::result(400,$e->getMessage());
        }
        return Common::result(200,"查询成功",$db);
    }

    public static function delnotes($data){
        try {
            $notes = Db::name('notes')->where('id', $data['id'])->delete();
        } catch (PDOException $e) {
             return Common::result(400,$e->getMessage());
        } catch (Exception $e) {
             return Common::result(400,$e->getMessage());
        }
        if ($notes>0){
            return Common::result(200,"删除成功");
        }else{
            return Common::result(400,'删除失败');
        }
    }

}